package com.study.cloud.controller;

import com.study.cloud.entities.CommonResult;
import com.study.cloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
@RequestMapping(value = "/consumer")
public class OrderController {
    public static final String INVOKE_URL = "http://consul-provider-payment";

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/addPayment", method = RequestMethod.GET)
    public CommonResult<Payment> addPayment(Payment payment) {
        return restTemplate.postForObject(INVOKE_URL + "/payment/addPayment", payment, CommonResult.class);
    }

    @RequestMapping(value = "/getPaymentById/{id}", method = RequestMethod.GET)
    public CommonResult<Payment> getPaymentById(@PathVariable Long id) {
        return restTemplate.getForObject(INVOKE_URL + "/payment/getPaymentById/" + id, CommonResult.class);
    }
}
